from home.models import PositionType
from jobs.models import Position
from django.db import models


# Create your models here.
class recruiterManagement(models.Model):
    name = models.CharField(max_length=50, verbose_name="姓名")
    position = models.ForeignKey(Position, on_delete=models.CASCADE, verbose_name="招聘职位")
    address = models.CharField(max_length=100, verbose_name="地址")
    recruitmentPositions = models.ForeignKey(PositionType, on_delete=models.CASCADE, verbose_name="招聘职位")
    sort = models.IntegerField(default=0, verbose_name='排序')
    isdel = models.BooleanField(default=False, verbose_name='是否删除')
    addtime = models.DateTimeField(auto_now_add=True, verbose_name='添加时间')
    field1 = models.CharField(max_length=50, verbose_name="字段1", null=True, blank=True)
    field2 = models.CharField(max_length=50, verbose_name="字段2", null=True, blank=True)
    field3 = models.CharField(max_length=50, verbose_name="字段3", null=True, blank=True)

    class Meta:
        verbose_name = "招聘管理"
        verbose_name_plural = verbose_name
        db_table = "recruiter"


class jobRecruiter(models.Model):
    recruiter = models.ForeignKey(recruiterManagement, on_delete=models.CASCADE, verbose_name="招聘人员",
                                  related_name="job_relations")
    job = models.OneToOneField(Position, on_delete=models.CASCADE, verbose_name="职位",
                               related_name="recruiter_relation")

    class Meta:
        db_table = "job_recruiter"
        verbose_name = "职位招聘人员"
        verbose_name_plural = verbose_name
        unique_together = ("recruiter", "job")


class jobCategory(models.Model):
    category_code = models.CharField(max_length=50, verbose_name="分类代码", unique=True)
    name = models.CharField(max_length=50, verbose_name="分类名称")
    parent = models.ForeignKey('self', on_delete=models.CASCADE, null=True, blank=True, verbose_name="父级分类")

    class Meta:
        db_table = "job_category"
        verbose_name = "职位分类"
        verbose_name_plural = verbose_name
        ordering = ['category_code']
